package com.gz.springboot.config;

import com.gz.springboot.servlet.Filter_;
import com.gz.springboot.servlet.Listener_;
import com.gz.springboot.servlet.Servlet_;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.logging.Filter;

@Configuration(proxyBeanMethods = true) //单例的
public class RegisterConfig {

    //以使用ServletRegistrationBean方式注入servlet、filter、listen(web三大件)
    @Bean
    public ServletRegistrationBean servlet_() {
        Servlet_ servlet = new Servlet_();
        return new ServletRegistrationBean(servlet, "/servlet01","/servlet02");
    }

    @Bean
    public FilterRegistrationBean filter_() {
        Filter_ filter = new Filter_();
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(filter);
        filterRegistrationBean.setUrlPatterns(Arrays.asList("/css/*","/images/*"));
        return filterRegistrationBean;
    }

    @Bean
    public ServletListenerRegistrationBean listener_() {
        Listener_ listener = new Listener_();
        ServletListenerRegistrationBean listenerRegistrationBean = new ServletListenerRegistrationBean(listener);
        return listenerRegistrationBean;
    }
}
